package base.generic.demo09;

import java.util.ArrayList;
import java.util.Collection;

import org.junit.Test;

public class TestCase {
    @Test
    public void testCase1(){
        // 泛型明确写的时候,前后必须一致
        Collection<Object> c1 = new ArrayList<Object>();
//        Collection<Object> c2 = new ArrayList<Animal>();// 报错
//        Collection<Object> c3 = new ArrayList<Dog>();// 报错


        // ?在java中表示类型，而Object不是
        Collection<?> c4 = new ArrayList<Object>();
        Collection<?> c5 = new ArrayList<Animal>();
        Collection<?> c6 = new ArrayList<Dog>();

        // ? extends E: 向下限定，E及其子类
//        Collection<? extends Animal> c7 = new ArrayList<Object>();//报错，必须是Animal的子类
        Collection<? extends Animal> c8 = new ArrayList<Animal>();
        Collection<? extends Animal> c9 = new ArrayList<Dog>();

        // ? super E: 向上限定，E及其父类
        Collection<? super Animal> c10 = new ArrayList<Object>();
        Collection<? super Animal> c11 = new ArrayList<Animal>();
//        Collection<? super Animal> c12 = new ArrayList<Dog>();//报错，必须是Animal及其父类
    }
}
